package org.freemarker.core.validator;

import java.util.ArrayList;
import java.util.List;

import org.freemarker.core.model.Car;
import org.freemarker.core.model.Contact;
import org.freemarker.core.model.User;
import org.freemarker.core.service.CarService;
import org.freemarker.core.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;

public class Validator {
	
	
	@Autowired
	private CarService carService;
	private UserService userService;
	
	List<String> errors = new ArrayList<String>();
	
	public Validator(){
		
	}
	
	public List<String> checkContactData(Contact contact) {
		errors.clear();
		
		if (!contact.getSecurityNumber().matches("[0-9]+")) {
			errors.add("Security number must be a... number!");
		}
		
		if(contact.getSecurityNumber().equals("")){
			errors.add("Security number field may not be empty!\n");
		}
		if(contact.getFirstname().equals("")){
			errors.add("First name field may not be empty!\n");
		}
		if(contact.getLastname().equals("")){
			errors.add("Last name field may not be empty!\n");
		}
		if(contact.getEmail().equals("")){
			errors.add("Email field may not be empty!\n");
		}
		if(contact.getTelephone().equals("")){
			errors.add("Telephone field may not be empty!\n");
		}
		if(contact.getBirthdate()==null){
			errors.add("Birthday field may not be empty!\n");
		}
		
		return errors;
	}
	
	public List<String> checkCarData(Car car){
		errors.clear();
		if(car.getNumarMatricol().equals("")){
			errors.add("Plate number can not be empty!");
		}
		if(car.getMarca().equals("")){
			errors.add("Car brand can not be empty!");
		}
		if(car.getModel().equals("")){
			errors.add("Car model can not be empty!");
		}
		
		return errors;
		
	}
	
	public List<String> validateUser(User user){
		errors.clear();
		if(user.getUsername().equals("")){
			errors.add("User name can not be empty!");
		}
		if(user.getPassword().equals("")){
			errors.add("Password can not be empty!");
		}
		return errors;
	}
}
